package com.example.smartagriculture.controller;

import blockchain.json.BlockChainJson;
import blockchain.net.NetServerScanner;
import com.example.smartagriculture.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/blockchain")
public class BlockChainController {
    @PostMapping("/getAll")
    @Operation(description = "获取区块链所有区块数据")
    public Result getAll(){
        return Result.success(NetServerScanner.getAll());
    }
//    @PostMapping("/addOne")
//    @Operation(description = "添加一个区块")
//    public void add(String data){
//        NetServerScanner.add(data);
//    }


    public static void main(String[] args) {
        BlockChainJson blockChainJson = new BlockChainJson();
        blockChainJson.batchNumber = "avc-233-ccc";
        blockChainJson.temperature = "90";
        blockChainJson.humidity = "90";
        blockChainJson.personInCharge = "操作员博祖";
        blockChainJson.productID = "BoZuID-avc-233-ccc";
        blockChainJson.productionLocation = "师祖上海生产基地";
        blockChainJson.qualityInspector = "泽祖";
        blockChainJson.operatingTime = "2026";
        String jsonstring = blockChainJson.toJsonString();
        System.out.println(jsonstring);
        BlockChainJson blockChainJson2 = new BlockChainJson(jsonstring);
        System.out.println(blockChainJson2.productID);
    }
}
